# Maintainer: Andrew Sun <adsun701@gmail.com>

_realname=tox
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=3.14.6
pkgrel=1
pkgdesc="Python virtualenv management and testing tool (mingw-w64)"
arch=('any')
url="https://tox.readthedocs.io"
license=('GPL2')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-py"
         "${MINGW_PACKAGE_PREFIX}-python-six"
         #"${MINGW_PACKAGE_PREFIX}-python-virtualenv"
         "${MINGW_PACKAGE_PREFIX}-python-setuptools"
         "${MINGW_PACKAGE_PREFIX}-python-setuptools-scm"
         "${MINGW_PACKAGE_PREFIX}-python-filelock"
         "${MINGW_PACKAGE_PREFIX}-python-toml"
         "${MINGW_PACKAGE_PREFIX}-python-pluggy")
makedepends=("util-linux")
install=${_realname}3-${CARCH}.install
options=('staticlibs' 'strip' '!debug')
source=("${_realname}-${pkgver}.tar.gz"::"https://pypi.io/packages/source/t/tox/${_realname}-${pkgver}.tar.gz")
sha256sums=('a4a6689045d93c208d77230853b28058b7513f5123647b67bf012f82fa168303')

prepare() {
  find ${_realname}-${pkgver} -name "*.pyc" -delete
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
}

build() {
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

#This hangs when I try this.
#check() {
#  cd "${srcdir}/python-build-${CARCH}" 
#  msg "Python build for ${CARCH}" 
#  ${MINGW_PREFIX}/bin/virtualenv "$srcdir/pyvenv" --system-site-packages
#  . "$srcdir/pyvenv/bin/activate"
#  ${MINGW_PREFIX}/bin/python setup.py install
#  ${MINGW_PREFIX}/bin/python setup.py pytest
#
#}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/COPYING"

  local PREFIX_WIN=$(cygpath -wm ${MINGW_PREFIX})
  # fix python command in files
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*.py; do
    sed -e "s|${PREFIX_WIN}/bin/|${MINGW_PREFIX}/bin/|g" -i ${_f}
  done
}
